<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑秒杀商品</title>
	<#include "/common/vue_resource.ftl">
</head>
<body>
<div id="app" v-cloak>
	<div class="ui-form">
		<form class="layui-form" @submit.prevent="submitForm()" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">秒杀时间段<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<select v-model="record.flashPromotionSessionId" class="layui-input">
						<option value="">请选择</option>
						<option :value="item.id" v-for="(item, index) in flashPromotionSessionList">{{item.name}}</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">商品名称<span class="ui-request">*</span></label>
				<div class="layui-input-inline" style="width:390px;">
					<input type="text" v-model="record.productName" class="layui-input" readonly/>
				</div>
				<button type="button" class="layui-btn layui-btn-normal" @click="showProductDialog">选择商品</button>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">秒杀价格<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" v-model="record.flashPromotionPrice" placeholder="请输入限时购价格" class="layui-input"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">秒杀数量<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" v-model="record.flashPromotionCount" placeholder="请输入限时购数量" class="layui-input"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">限购数量<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" v-model="record.flashPromotionLimit" placeholder="请输入每人限购数量" class="layui-input"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<div class="layui-input-block">
					<input type="text" v-model="record.sort" placeholder="请输入排序" class="layui-input"/>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</div>
<script>
	var app = new Vue({
		el: '#app',
		data: {
			showTypes: false,
			record: {
				id: '${params.id!}',
				flashPromotionId: '${params.flashPromotionId!}',
				flashPromotionSessionId: '',
				productId: '',
				productName: '',
				flashPromotionPrice: '',
				flashPromotionCount: '',
				flashPromotionLimit: '1',
				sort: '0',
			},
			flashPromotionSessionList: [],
		},
		mounted: function () {
			this.init();
			this.loadFlashPromotionSession();
		},
		methods: {
			init:function(){
				var that = this;
				/*laydate.render({elem: '#beginDate', type:'datetime', done:function (value) {
						that.record.beginDate = value;
					}});*/
			},
			loadFlashPromotionSession: function () {
				var that = this;
				$.http.post('${params.contextPath}/web/smsFlashPromotionSession/queryList.json').then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					that.flashPromotionSessionList = data.data;
					that.loadData();
				});
			},
			loadData: function () {
				if (!'${params.id!}') {
					return;
				}
				var that = this;
				$.http.post('${params.contextPath}/web/smsFlashPromotionProductRelation/query.json', {id: '${params.id!}'}).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var item = data.data;
					for (var key in  that.record) {
						that.record[key] = item[key];
					}
				});
			},
			submitForm: function () {
				$.http.post('${params.contextPath}/web/smsFlashPromotionProductRelation/<#if (params.id)??>modify<#else>save</#if>.json', this.record).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var alt = layer.alert(data.message || "操作成功", function () {
						parent.app.loadData();
						parent.layer.closeAll();
						layer.close(alt);
					});
				});
			},
			showProductDialog: function () {
				var url = "${params.contextPath!}/view/business/pmsProduct/pmsProduct_dialog.htm";
				DialogManager.open({url: url, width: '90%', height: '90%', title: '选择商品'});
			},
			productSelectCallBack: function (row) {
				this.record.productId = row.id;
				this.record.productName = row.name;
				DialogManager.closeAll();
			}
		}
	});
</script>
</body>

</html>
